import { useDeviceRoleStore } from '@/dataset/device-role/store'

let store : ReturnType<typeof useDeviceRoleStore> = null

export const DeviceRoleUtil = {
  // 获取权限对象
  getRole (deviceId: string) {
    store ??= useDeviceRoleStore()
    return store.deviceRole.get(deviceId)
  },
  // 更新权限
  updateRole () {
    useDeviceRoleStore().updateDeviceRole()
  },
  // 是否是所有者
  isAdmin (deviceId: string) {
    return this.getRole(deviceId)?.roleType === '4'
  },
  // 是否是管理着
  isManager (deviceId: string) {
    return ['3', '4'].includes(this.getRole(deviceId)?.roleType)
  },
  // 是否是管理着
  isOnlyManager (deviceId: string) {
    return ['3'].includes(this.getRole(deviceId)?.roleType)
  },
  // 是否是可控制
  isControl (deviceId: string) {
    return ['1', '3', '4'].includes(this.getRole(deviceId)?.roleType)
  }
}
